﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ApiData.Common
{
    /// <summary>
    /// 随机字符串
    /// </summary>
    public static class RanString
    {
        private static string RanNumber = "0123456789";
        private static string RanLetter = "abcdefghujklmnopqrstuvwxyz";
        private static string RanUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        /// <summary>
        /// 获取指定长度的随机字符串[数字]
        /// </summary>
        /// <param name="length">长度</param>
        /// <returns>随机字符串</returns>
        public static string RandomNumber(int length)
        {
            string result = string.Empty;
            Random ran = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < length; i++)
            {
                result += RanNumber[ran.Next(0, RanNumber.Length)];
            }
            return result;
        }
        /// <summary>
        /// 获取指定长度的随机字符串[小写字母]
        /// </summary>
        /// <param name="length">长度</param>
        /// <returns>随机字符串</returns>
        public static string RandomLetter(int length)
        {
            string result = string.Empty;
            Random ran = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < length; i++)
            {
                result += RanLetter[ran.Next(0, RanLetter.Length)];
            }
            return result;
        }
        /// <summary>
        /// 获取指定长度的随机字符串[大写字母]
        /// </summary>
        /// <param name="length">长度</param>
        /// <returns>随机字符串</returns>
        public static string RandomUpper(int length)
        {
            string result = string.Empty;
            Random ran = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < length; i++)
            {
                result += RanUpper[ran.Next(0, RanUpper.Length)];
            }
            return result;
        }
        /// <summary>
        /// 获取指定长度的随机字符串[小写字母/大写字母]
        /// </summary>
        /// <param name="length">长度</param>
        /// <returns>随机字符串</returns>
        public static string RandomLetterAndUpper(int length)
        {
            string result = string.Empty;
            string Active = RanLetter + RanUpper;
            Random ran = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < length; i++)
            {
                result += Active[ran.Next(0, Active.Length)];
            }
            return result;
        }
        /// <summary>
        /// 获取指定长度的随机字符串[包含数字/小写字母/大写字母]
        /// </summary>
        /// <param name="length">长度</param>
        /// <returns>随机字符串</returns>
        public static string RandomAll(int length)
        {
            string result = string.Empty;
            string Active = RanNumber + RanLetter + RanUpper;
            Random ran = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < length; i++)
            {
                result += Active[ran.Next(0, Active.Length)];
            }
            return result;
        }
        /// <summary>
        /// 获取指定长度的随机字符串[数字/小写字母]
        /// </summary>
        /// <param name="length">长度</param>
        /// <returns>随机字符串</returns>
        public static string RandomNumberAndLetter(int length)
        {
            string result = string.Empty;
            string Active = RanNumber + RanLetter;
            Random ran = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < length; i++)
            {
                result += Active[ran.Next(0, Active.Length)];
            }
            return result;
        }
        /// <summary>
        /// 获取指定长度的随机字符串[数字/大写字母]
        /// </summary>
        /// <param name="length">长度</param>
        /// <returns>随机字符串</returns>
        public static string RandomNumberAndUpper(int length)
        {
            string result = string.Empty;
            string Active = RanNumber + RanUpper;
            Random ran = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < length; i++)
            {
                result += Active[ran.Next(0, Active.Length)];
            }
            return result;
        }
    }
}
